home *** CD-ROM | disk | FTP | other *** search
/ Multimedia Jumpstart / Multimedia Microsoft Jumpstart Version 1.1a (Microsoft).BIN / develpmt / sdk / vfw11.win / vfwdk / debug.c2_ / debug.bin
Encoding:
Text File  |  1993-11-19  |  6.3 KB  |  293 lines

  1. //==========================================================================;
  2. //
  3. //  THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  4. //  KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  5. //  IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
  6. //  PURPOSE.
  7. //
  8. //  Copyright (c) 1992, 1993  Microsoft Corporation.  All Rights Reserved.
  9. //
  10. //--------------------------------------------------------------------------;
  11. //
  12. //  debug.c
  13. //
  14. //  Description:
  15. //      This file contains code yanked from several places to provide debug
  16. //      support that works in win 16 and win 32.
  17. //
  18. //
  19. //==========================================================================;
  20.  
  21. #ifdef DEBUG
  22.  
  23. #include <windows.h>
  24. #include <windowsx.h>
  25. #include <stdarg.h>
  26. #include "debug.h"
  27.  
  28.  
  29. //
  30. //  since we don't UNICODE our debugging messages, use the ASCII entry
  31. //  points regardless of how we are compiled.
  32. //
  33. #ifdef WIN32
  34.     #include <wchar.h>
  35. #else
  36.     #define lstrcatA            lstrcat
  37.     #define lstrlenA            lstrlen
  38.     #define wvsprintfA          wvsprintf
  39.     #define GetProfileIntA      GetProfileInt
  40.     #define OutputDebugStringA  OutputDebugString
  41. #endif
  42.  
  43. //
  44. //
  45. //
  46. BOOL    __gfDbgEnabled          = TRUE;         // master enable
  47. UINT    __guDbgLevel            = 0;            // current debug level
  48.  
  49.  
  50. //--------------------------------------------------------------------------;
  51. //  
  52. //  void DbgVPrintF
  53. //  
  54. //  Description:
  55. //  
  56. //  
  57. //  Arguments:
  58. //      LPSTR szFormat:
  59. //  
  60. //      LPSTR va:
  61. //  
  62. //  Return (void):
  63. //      No value is returned.
  64. //  
  65. //--------------------------------------------------------------------------;
  66.  
  67. void FAR CDECL DbgVPrintF
  68. (
  69.     LPSTR                   szFormat,
  70.     LPSTR                   va
  71. )
  72. {
  73.     char                ach[DEBUG_MAX_LINE_LEN];
  74.     BOOL                fDebugBreak = FALSE;
  75.     BOOL                fPrefix     = TRUE;
  76.     BOOL                fCRLF       = TRUE;
  77.  
  78.     ach[0] = '\0';
  79.  
  80.     for (;;)
  81.     {
  82.         switch (*szFormat)
  83.         {
  84.             case '!':
  85.                 fDebugBreak = TRUE;
  86.                 szFormat++;
  87.                 continue;
  88.  
  89.             case '`':
  90.                 fPrefix = FALSE;
  91.                 szFormat++;
  92.                 continue;
  93.  
  94.             case '~':
  95.                 fCRLF = FALSE;
  96.                 szFormat++;
  97.                 continue;
  98.         }
  99.  
  100.         break;
  101.     }
  102.  
  103.     if (fDebugBreak)
  104.     {
  105.         ach[0] = '\007';
  106.         ach[1] = '\0';
  107.     }
  108.  
  109.     if (fPrefix)
  110.     {
  111.         lstrcatA(ach, DEBUG_MODULE_NAME ": ");
  112.     }
  113.  
  114.     wvsprintfA(ach + lstrlenA(ach), szFormat, (LPSTR)va);
  115.  
  116.     if (fCRLF)
  117.     {
  118.         lstrcatA(ach, "\r\n");
  119.     }
  120.  
  121.     OutputDebugStringA(ach);
  122.  
  123.     if (fDebugBreak)
  124.     {
  125.         DebugBreak();
  126.     }
  127. } // DbgVPrintF()
  128.  
  129.  
  130. //--------------------------------------------------------------------------;
  131. //  
  132. //  void dprintf
  133. //  
  134. //  Description:
  135. //      dprintf() is called by the DPF() macro if DEBUG is defined at compile
  136. //      time. It is recommended that you only use the DPF() macro to call
  137. //      this function--so you don't have to put #ifdef DEBUG around all
  138. //      of your code.
  139. //      
  140. //  Arguments:
  141. //      UINT uDbgLevel:
  142. //  
  143. //      LPSTR szFormat:
  144. //  
  145. //  Return (void):
  146. //      No value is returned.
  147. //
  148. //--------------------------------------------------------------------------;
  149.  
  150. void FAR CDECL dprintf
  151. (
  152.     UINT                    uDbgLevel,
  153.     LPSTR                   szFormat,
  154.     ...
  155. )
  156. {
  157.     va_list va;
  158.  
  159.     if (!__gfDbgEnabled || (__guDbgLevel < uDbgLevel))
  160.         return;
  161.  
  162.     va_start(va, szFormat);
  163.     DbgVPrintF(szFormat, (LPSTR)va);
  164.     va_end(va);
  165. } // dprintf()
  166.  
  167.  
  168. //--------------------------------------------------------------------------;
  169. //  
  170. //  BOOL DbgEnable
  171. //  
  172. //  Description:
  173. //  
  174. //  
  175. //  Arguments:
  176. //      BOOL fEnable:
  177. //  
  178. //  Return (BOOL):
  179. //      Returns the previous debugging state.
  180. //  
  181. //--------------------------------------------------------------------------;
  182.  
  183. BOOL WINAPI DbgEnable
  184. (
  185.     BOOL                    fEnable
  186. )
  187. {
  188.     BOOL                fOldState;
  189.  
  190.     fOldState      = __gfDbgEnabled;
  191.     __gfDbgEnabled = fEnable;
  192.  
  193.     return (fOldState);
  194. } // DbgEnable()
  195.  
  196.  
  197. //--------------------------------------------------------------------------;
  198. //  
  199. //  UINT DbgSetLevel
  200. //  
  201. //  Description:
  202. //  
  203. //  
  204. //  Arguments:
  205. //      UINT uLevel:
  206. //  
  207. //  Return (UINT):
  208. //      Returns the previous debugging level.
  209. //  
  210. //--------------------------------------------------------------------------;
  211.  
  212. UINT WINAPI DbgSetLevel
  213. (
  214.     UINT                    uLevel
  215. )
  216. {
  217.     UINT                uOldLevel;
  218.  
  219.     uOldLevel    = __guDbgLevel;
  220.     __guDbgLevel = uLevel;
  221.  
  222.     return (uOldLevel);
  223. } // DbgSetLevel()
  224.  
  225.  
  226. //--------------------------------------------------------------------------;
  227. //  
  228. //  UINT DbgGetLevel
  229. //  
  230. //  Description:
  231. //  
  232. //  
  233. //  Arguments:
  234. //      None.
  235. //  
  236. //  Return (UINT):
  237. //      Returns the current debugging level.
  238. //  
  239. //--------------------------------------------------------------------------;
  240.  
  241. UINT WINAPI DbgGetLevel
  242. (
  243.     void
  244. )
  245. {
  246.     return (__guDbgLevel);
  247. } // DbgGetLevel()
  248.  
  249.  
  250. //--------------------------------------------------------------------------;
  251. //  
  252. //  UINT DbgInitialize
  253. //  
  254. //  Description:
  255. //  
  256. //  
  257. //  Arguments:
  258. //      BOOL fEnable:
  259. //  
  260. //  Return (UINT):
  261. //      Returns the debugging level that was set.
  262. //  
  263. //--------------------------------------------------------------------------;
  264.  
  265. UINT WINAPI DbgInitialize
  266. (
  267.     BOOL                    fEnable
  268. )
  269. {
  270.     UINT                uLevel;
  271.  
  272.     uLevel = GetProfileIntA(DEBUG_SECTION, DEBUG_MODULE_NAME, (UINT)-1);
  273.     if ((UINT)-1 == uLevel)
  274.     {
  275.         //
  276.         //  if the debug key is not present, then force debug output to
  277.         //  be disabled. this way running a debug version of a component
  278.         //  on a non-debugging machine will not generate output unless
  279.         //  the debug key exists.
  280.         //
  281.         uLevel  = 0;
  282.         fEnable = FALSE;
  283.     }
  284.  
  285.     DbgSetLevel(uLevel);
  286.     DbgEnable(fEnable);
  287.  
  288.     return (__guDbgLevel);
  289. } // DbgInitialize()
  290.  
  291. #endif // #ifdef DEBUG
  292.  
  293.